#include <iostream>
#include <functional>

class LazyFactorial {
private:
    int n;
    std::function<int()> compute;

public:
    LazyFactorial(int num) : n(num) {
        compute = [this]() {
            int result = 1;
            for (int i = 1; i <= n; ++i) {
                result *= i;
            }
            return result;
        };
    }

    int getValue() {
        return compute();
    }
};

int main() {
    LazyFactorial lazyFact5(5); // 计算阶乘5!
    std::cout << "5! = " << lazyFact5.getValue() << std::endl;

    LazyFactorial lazyFact10(10); // 计算阶乘10!
    std::cout << "10! = " << lazyFact10.getValue() << std::endl;

    return 0;
}
